import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class MePage extends StatelessWidget {
  const MePage({super.key});

  static const MethodChannel _channel = MethodChannel('com.ytm.flutterapp');

  static final List menuList = [
    {"title": "opencv test", "icon": Icons.telegram, "route": "/opencv-test"},
    {
      "title": "image to contours",
      "icon": Icons.image,
      "route": "/image-to-contours"
    },
    {"title": "image edit", "icon": Icons.edit, "route": "/image-edit"},
    {
      "title": "open album by method channel",
      "icon": Icons.album,
      "onTap": () => {_channel.invokeMethod("openAlbum")}
    },
    {"title": "paint editor", "icon": Icons.piano, "route": "/paint-editor"},
    {"title": "white board", "icon": Icons.draw, "route": "/white-board"},
  ];

  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
      appBar: AppBar(
        title: const Text("Me"),
      ),
      body: ListView.builder(
        itemCount: menuList.length,
        itemBuilder: (context, index) {
          return Card(
            child: ListTile(
              leading: Icon(menuList[index]["icon"]),
              title: Text(menuList[index]["title"]),
              onTap: () {
                menuList[index]["onTap"]?.call();
                final route = menuList[index]["route"];
                if (route == null) return;
                Navigator.pushNamed(context, menuList[index]["route"]);
              },
            ),
          );
        },
      ),
    ));
  }
}
